<template>
  <div>
    <el-card shadow="never">
      <el-skeleton :loading="loading" animated>
        <el-row :gutter="20" justify="space-between">
          <el-col :xl="12" :lg="12" :md="12" :sm="24" :xs="24">
            <div class="flex items-center">
              <img :src="avatar" alt="" class="w-70px h-70px rounded-[50%] mr-20px" />
              <div>
                <div class="text-20px text-700">
                  {{ t('workplace.welcome') }} {{ username }} {{ t('workplace.happyDay') }}
                </div>
                <div class="mt-10px text-14px text-gray-500">
                  {{ t('workplace.toady') }}，20℃ - 32℃！
                </div>
              </div>
            </div>
          </el-col>
          <!--   <el-col :xl="12" :lg="12" :md="12" :sm="24" :xs="24">
            <div class="flex h-70px items-center justify-end <sm:mt-10px">
              <div class="px-8px text-right">
                <div class="text-14px text-gray-400 mb-20px">{{ t('workplace.project') }}</div>
                <CountTo
                  class="text-20px"
                  :start-val="0"
                  :end-val="totalSate.project"
                  :duration="2600"
                />
              </div>
              <el-divider direction="vertical" />
              <div class="px-8px text-right">
                <div class="text-14px text-gray-400 mb-20px">{{ t('workplace.toDo') }}</div>
                <CountTo
                  class="text-20px"
                  :start-val="0"
                  :end-val="totalSate.todo"
                  :duration="2600"
                />
              </div>
              <el-divider direction="vertical" border-style="dashed" />
              <div class="px-8px text-right">
                <div class="text-14px text-gray-400 mb-20px">{{ t('workplace.access') }}</div>
                <CountTo
                  class="text-20px"
                  :start-val="0"
                  :end-val="totalSate.access"
                  :duration="2600"
                />
              </div>
            </div>
          </el-col> -->
        </el-row>
      </el-skeleton>
    </el-card>

    <!-- 我的系统卡片 -->
    <!-- <el-card class="box-card">
      <template #header>
        <div class="card-header header-icon">
          <div class="icon-blue">
            <i class="el-icon-menu"></i>
          </div>
          <p>{{ autoList.platformName ? autoList?.platformName : '平台应用' }}</p>
        </div>
      </template>

      <div class="card-body">
        <div class="platform">
          <div class="sys-div" v-for="index in autoList.dataList" :key="index.pageNo">
            <a :href="index.url + '?auto=' + objToBase64(index)" target="_self">
              <div class="img"><img class="sys-img" :src="index.photo" alt="" /></div>
              <div class="platform-title">
                <p>{{ index.pageDesc }}</p>
                <p class="samllTitle">{{ index.hint }}</p>
              </div>
            </a>
          </div>
        </div>
      </div>
    </el-card> -->
  </div>
</template>
<script setup lang="ts" name="Home">
import { set } from 'lodash-es'
import { EChartsOption } from 'echarts'
// import { Base64 } from 'js-base64'
// import { useUserStore } from '@/store/modules/user'
//import { useWatermark } from '@/hooks/web/useWatermark'
import avatarImg from '@/assets/imgs/avatar.gif'
import type { Notice, Project, Shortcut, WorkplaceTotal } from './types'
import { barOptions, pieOptions } from './echarts-data'
import { getUserProfile } from '@/api/system/user/profile'
import { useUserStore } from '@/store/modules/user'
const { t } = useI18n()
const userStore = useUserStore()
//const { setWatermark } = useWatermark()
const loading = ref(true)
const avatar = userStore.getUser.avatar ? userStore.getUser.avatar : avatarImg
const username = userStore.getUser.nickname
const pieOptionsData = reactive<EChartsOption>(pieOptions) as EChartsOption
// 获取统计数
let totalSate = reactive<WorkplaceTotal>({
  project: 0,
  access: 0,
  todo: 0
})

const getCount = async () => {
  const data = {
    project: 40,
    access: 2340,
    todo: 10
  }
  totalSate = Object.assign(totalSate, data)
}

// 获取项目数
let projects = reactive<Project[]>([])

const getProject = async () => {
  const data = [
    {
      name: 'Github',
      icon: 'akar-icons:github-fill',
      message: 'workplace.introduction',
      personal: 'Archer',
      time: new Date()
    },
    {
      name: 'Vue',
      icon: 'logos:vue',
      message: 'workplace.introduction',
      personal: 'Archer',
      time: new Date()
    },
    {
      name: 'Angular',
      icon: 'logos:angular-icon',
      message: 'workplace.introduction',
      personal: 'Archer',
      time: new Date()
    },
    {
      name: 'React',
      icon: 'logos:react',
      message: 'workplace.introduction',
      personal: 'Archer',
      time: new Date()
    },
    {
      name: 'Webpack',
      icon: 'logos:webpack',
      message: 'workplace.introduction',
      personal: 'Archer',
      time: new Date()
    },
    {
      name: 'Vite',
      icon: 'vscode-icons:file-type-vite',
      message: 'workplace.introduction',
      personal: 'Archer',
      time: new Date()
    }
  ]
  projects = Object.assign(projects, data)
}

// 获取通知公告
let notice = reactive<Notice[]>([])
const getNotice = async () => {
  const data = [
    {
      title: '系统升级版本',
      type: '通知',
      keys: ['通知', '升级'],
      date: new Date()
    },
    {
      title: '系统凌晨维护',
      type: '公告',
      keys: ['公告', '维护'],
      date: new Date()
    },
    {
      title: '系统升级版本',
      type: '通知',
      keys: ['通知', '升级'],
      date: new Date()
    },
    {
      title: '系统凌晨维护',
      type: '公告',
      keys: ['公告', '维护'],
      date: new Date()
    }
  ]
  notice = Object.assign(notice, data)
}

// 获取快捷入口
let shortcut = reactive<Shortcut[]>([])

const getShortcut = async () => {
  const data = [
    {
      name: 'Github',
      icon: 'akar-icons:github-fill',
      url: 'github.io'
    },
    {
      name: 'Vue',
      icon: 'logos:vue',
      url: 'vuejs.org'
    },
    {
      name: 'Vite',
      icon: 'vscode-icons:file-type-vite',
      url: 'https://vitejs.dev/'
    },
    {
      name: 'Angular',
      icon: 'logos:angular-icon',
      url: 'github.io'
    },
    {
      name: 'React',
      icon: 'logos:react',
      url: 'github.io'
    },
    {
      name: 'Webpack',
      icon: 'logos:webpack',
      url: 'github.io'
    }
  ]
  shortcut = Object.assign(shortcut, data)
}

// 用户来源
const getUserAccessSource = async () => {
  const data = [
    { value: 335, name: 'analysis.directAccess' },
    { value: 310, name: 'analysis.mailMarketing' },
    { value: 234, name: 'analysis.allianceAdvertising' },
    { value: 135, name: 'analysis.videoAdvertising' },
    { value: 1548, name: 'analysis.searchEngines' }
  ]
  set(
    pieOptionsData,
    'legend.data',
    data.map((v) => t(v.name))
  )
  pieOptionsData!.series![0].data = data.map((v) => {
    return {
      name: t(v.name),
      value: v.value
    }
  })
}
const barOptionsData = reactive<EChartsOption>(barOptions) as EChartsOption

// 周活跃量
const getWeeklyUserActivity = async () => {
  const data = [
    { value: 13253, name: 'analysis.monday' },
    { value: 34235, name: 'analysis.tuesday' },
    { value: 26321, name: 'analysis.wednesday' },
    { value: 12340, name: 'analysis.thursday' },
    { value: 24643, name: 'analysis.friday' },
    { value: 1322, name: 'analysis.saturday' },
    { value: 1324, name: 'analysis.sunday' }
  ]
  set(
    barOptionsData,
    'xAxis.data',
    data.map((v) => t(v.name))
  )
  set(barOptionsData, 'series', [
    {
      name: t('analysis.activeQuantity'),
      data: data.map((v) => v.value),
      type: 'bar'
    }
  ])
}

const getAllApi = async () => {
  await Promise.all([
    getCount(),
    getProject(),
    getNotice(),
    getShortcut(),
    getUserAccessSource(),
    getWeeklyUserActivity()
  ])
  loading.value = false
}

getAllApi()

// 我的系统卡片
const autoList = ref({
  platformName: undefined,
  dataList: [
    { pageNo: undefined, url: undefined, photo: undefined, pageDesc: undefined, hint: undefined }
  ]
})

onMounted(() => {
  getData()
})

// 获取数据
const getData = async () => {
  // const res = await getUserProfile()
  // autoList.value.dataList = res.modules
}
// const objToBase64 = (value) => {
//   return Base64.encode(JSON.stringify(value))
// }
</script>
<style scoped>
.content {
  min-width: 1550px;
}
/*控制台*/
.head {
  background-color: #ffffff;
  padding: 18px 24px;
  border-bottom: 1px solid #ebeef5;
  height: 12%;
}
/*用户信息*/
.head-info {
  display: flex;
  justify-content: space-between;
}
.info-right {
  display: flex;
  justify-content: right;
  width: 50%;
}
.right-item {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  margin-left: 24px;
  font-size: 26px;
}
.item-icon {
  display: flex;
  align-items: center;
  color: #808695;
  font-size: 14px;
}
.item-icon-orange {
  color: rgb(255, 169, 64);
  background-color: rgb(255, 247, 230);
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 100%;
  margin-right: 6px;
}
.item-icon-purple {
  color: rgb(114, 46, 209);
  background-color: rgb(249, 240, 255);
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 100%;
  margin-right: 6px;
}
.info-left {
  display: flex;
  width: 50%;
}
.info-left img {
  width: 380px;
  height: 110px;
  margin-right: 24px;
}
.left-name {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 12px;
}
.left-info {
  display: flex;
}
.left-info i {
  margin-right: 15px;
}
.module {
  display: flex;
  justify-content: space-evenly;
  height: 80%;
}
.module-left {
  flex: 5;
  padding: 20px 10px 0px 20px;
  height: 100%;
}
.module-right {
  flex: 1;
  padding: 20px 20px 0px 10px;
  height: 100%;
}
.header-icon {
  display: flex;
  align-items: center;
  color: #808695;
  font-size: 14px;
}
.icon-blue {
  color: rgb(64, 169, 255);
  background-color: rgb(230, 247, 255);
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 100%;
  margin-right: 6px;
}
.platform {
  display: flex;
  flex-wrap: wrap;
  padding-top: 30px;
  padding-bottom: 60px;
}
.sys-div {
  width: 24%;
  display: flex;
  justify-content: center;
  height: 180px;
  cursor: pointer;
}
.sys-div a {
  width: 80%;
  text-align: center;
  text-decoration: none;
}
.sys-div .img {
  height: 100%;
  display: flex;
  justify-content: center;
}
.sys-img {
  width: 260px;
  height: 100%;
}
.platform-title {
  line-height: 18px;
  font-weight: 600;
  font-size: 18px;
  margin-top: 15px;
  color: #000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.samllTitle {
  line-height: 12px;
  color: rgb(125, 131, 131);
  font-size: 12px;
  margin-top: 10px;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
}
.icon-yellow {
  color: rgb(255, 169, 64);
  background-color: rgb(255, 247, 230);
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 100%;
  margin-right: 6px;
}
.dealtDiv {
  display: flex;
  flex-direction: column;
}
.dealt {
  height: 48px;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
}
.dealt i {
  margin: 0 10px;
}
</style>
